<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>" />
		<title>添加客户</title>

		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=7" />
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />

		<style type="text/css">
#addForm label.error {
	font-size: 12px;
	color: red;
}
</style>

		<script type="text/javascript" src="<%=path%>/js/ui.js"></script>
		<link id="editCss" rel="stylesheet" type="text/css"
			href="<%=path%>/css/style.css" />
		<link id="editCss" rel="stylesheet" type="text/css"
			href="<%=path%>/css/right.css" />

		<script src="<%=path%>/js/jquery.js" type="text/javascript"></script>
		<script src="<%=path%>/js/jquery.validate.js" type="text/javascript"></script>

		<!-- validate begin  -->
		<script type="text/javascript">
	  $( jQuery.validator.addMethod("zip", function(value, element) { var tel = /^[0-9]{6}$/;  return this.optional(element) || (tel.test(value)); }, "请正确填写邮政编码"));
	
    $(
         function(){
               $('#addForm').validate({
             rules:{ customerID: {
                                        required:true,
                                        maxlength:8,
                                        onkeyup:false
                          }, company: {
                                        required:true,
                                        maxlength:30,
                                        onkeyup:false
                          }, contactName: {
                                        required:true,
                                        maxlength:30,
                                        onkeyup:false
                          },contactPhone:{
                                required:true,
                                number:true,
                                minlength:7,
                                maxlength:12,
                                onkeyup:false
                          }, postCode:{
                                 required:true,
                                 zip:true,
                                 onkeyup:false
                          }, contactEmail:{
							    required:true,
                                email:true,
                                onkeyup:false
                          }, street:{
									   required:true,
									minlength:1,
                                maxlength:50,
                                onkeyup:false
						},city:{
									   required:true,   
									 minlength:1,
                                maxlength:50,
                                onkeyup:false
						}, country:{
									  required:true,   
									minlength:1,
                                maxlength:50,
                                onkeyup:false
						}
                    },messages:{
									customerID: {required:"请输入ID!",maxlength:"太长"},
                                    company: {required:"请输入公司名!" ,maxlength:"太长"},
                                    contactName:{ required:"请填写联系人!" ,maxlength:"太长"},
									contactEmail:{ required:"请填写邮箱!",email:"邮箱格式错误!" ,maxlength:"太长",minlength:"太短"},
									street:{ required:"请填写街道!",maxlength:"太长",minlength:"太短" },
                                    city:{ required:"请填写城市!",maxlength:"太长",minlength:"太短" },
									country:{ required:"请填写国家!",maxlength:"太长",minlength:"太短" },
                                    contactPhone:{number:"请填写数字!",required:"请填写常用号码!",maxlength:"太长",minlength:"太短" },
                                    postCode:{ required:"请填写邮政编码!", zip:"邮编格式错误!" }
                           },submitHandler: function(form) { 
                        	   doVali();
                        	  if(isOkVali()==true){
                        		     form.submit();
                            	  }
                              
                               }
                    }); });	
	</script>
		<!-- validate end  -->

		<script type="text/javascript">
        
	function isOkVali(){
			if(xmlHttpRequest.readyState==4&&xmlHttpRequest.status==200){
				if(xmlHttpRequest.responseText=="ok"){
				$("#showVali").text("可以使用");
				return true;
				}
				else if(xmlHttpRequest.responseText=="isExsit"){
					$("#showVali").html("<font style='color:red;'>ID已存在</font>");
					return false;
				}
					return false;
			
			}
	}
	function doVali(){
		var valr=$("#customerID");
		if(valr!=null&&$.trim(valr.val()).length>=3){
			var reg = /[\u4e00-\u9fa5]/; 
			 if(reg.test(valr.val())){
				 	alert("id不能含有中文。");
				 	valr.focus();
				 	return false ;
				 }else{
					var url ="<%=path%>/servlet/AddServlet?key=isExistCus&cusId="+valr.val();
					 if (window.XMLHttpRequest) {   
				        　　 xmlHttpRequest = new XMLHttpRequest();   
				        　　 }else if (window.ActiveXObject) {   
				        　　  xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");   
				        　　 }   
				        　　 if(xmlHttpRequest){   
							        		xmlHttpRequest.open("post",url,false);
					        		xmlHttpRequest.onreadystatechange=isOkVali;
					        		xmlHttpRequest.send(null);
		        　　 }
			        }   	
			}else{
					alert("ID填写不完整!");
					valr.focus();
					return ;
				}
	
	}
	
	
	</script>
	</head>
	<body class="bg">
		<div id="nav" class="crumbs">
			当前位置：
			<a href="<%=path%>/servlet/SrhCus" class="title">客户管理</a>> 添加客户
		</div>

		<div class="search ctitle">
			<div class="tab">
				<span class="right"></span>
				<span class="font-blue14pxb">添加客户</span>
			</div>
		</div>

		<div class="tableBox fwidth">
			<form id="addForm" method="post"
				action="<%=path%>/servlet/AddServlet">
				<input type="hidden" name="key" id="key" value="cus" />
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<th class="h">
							公司ID
						</th>
						<td class="text_left">
							<input id="customerID" name="customerID" type="text"
								maxlength="8" value="" style="width: 150px; color: #325f86;"
								onblur="doVali()" />
							<span id="showVali" class="svalid"></span>

						</td>

					</tr>
					<tr>
						<th class="h">
							公司名称
						</th>
						<td class="text_left">
							<input name="company" type="text" maxlength="30" value=""
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>
					<tr>
						<th class="h">
							联系人
						</th>
						<td class="text_left">
							<input maxlength="30" id="contactName" name="contactName"
								type="text" value="" style="width: 150px; color: #325f86;"
								islist=true list="1" autocomplete="off" />
						</td>
					</tr>

					<tr>
						<th class="h">
							联系电话
						</th>
						<td class="text_left">
							<input maxlength="20" name="contactPhone" type="text" value=""
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>

					<tr>
						<th class="h">
							传 真
						</th>
						<td class="text_left">
							<input maxlength="20" name="contactFax" type="text" value=""
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>

					<tr>
						<th class="h">
							邮 箱
						</th>
						<td class="text_left">
							<input maxlength="30" name="contactEmail" type="text" value=""
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>
					<tr>

						<th class="h">
							街 道
						</th>
						<td class="text_left">
							<input maxlength="50" name="street" type="text" value=""
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>

					<tr>
						<th class="h">
							城 市
						</th>
						<td class="text_left">
							<input name="city" type="text" value="" maxlength="30"
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>

					<tr>
						<th class="h">
							国 家
						</th>
						<td class="text_left">
							<input name="country" type="text" value="" maxlength="30"
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>

					<tr>
						<th class="h">
							邮 编
						</th>
						<td class="text_left">
							<input name="postCode" type="text" value="" maxlength="6"
								style="width: 150px; color: #325f86;" />
						</td>
					</tr>

					<tr class="footer">
						<td colspan="2" align="center">
							<input type="submit" name="save" value="添 加" class="button" />
						</td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>
